<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Memory Management Unit Files mmu_&lt;device&gt;.c</title>
<title>CMSIS-Core (Cortex-A): Memory Management Unit Files mmu_&lt;device&gt;.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 46px;">
  <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMSIS-Core (Cortex-A)
   &#160;<span id="projectnumber">Version 1.1.4</span>
   </div>
   <div id="projectbrief">CMSIS-Core support for Cortex-A processor-based devices</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
    <ul class="tablist">
      <script type="text/javascript">
		<!--
		writeComponentTabs.call(this);
		//-->
      </script>
	  </ul>
</div>
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
      <li><a href="modules.html"><span>Reference</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('mmu_c_pg.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Memory Management Unit Files mmu_&lt;device&gt;.c </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><pre class="fragment">/**************************************************************************//**
 * @file     system_Device.c
 * @brief    MMU Configuration
 *           Device &lt;DeviceAbbreviation&gt;
 * @version  V1.1.0
 * @date     23. November 2018
 ******************************************************************************/
/*
 * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* Memory map description

   ToDo: add in this file your device memory map description
         following is an example of a Cortex-A9 Arm FVP device

                                                     Memory Type
0xFFFFFFFF |--------------------------|             ------------
           |       FLAG SYNC          |             Device Memory
0xFFFFF000 |--------------------------|             ------------
           |         Fault            |                Fault
0xFFF00000 |--------------------------|             ------------
           |                          |                Normal
           |                          |
           |      Daughterboard       |
           |         memory           |
           |                          |
0x80505000 |--------------------------|             ------------
           |TTB (L2 Sync Flags   ) 4k |                Normal
0x80504C00 |--------------------------|             ------------
           |TTB (L2 Peripherals-B) 16k|                Normal
0x80504800 |--------------------------|             ------------
           |TTB (L2 Peripherals-A) 16k|                Normal
0x80504400 |--------------------------|             ------------
           |TTB (L2 Priv Periphs)  4k |                Normal
0x80504000 |--------------------------|             ------------
           |    TTB (L1 Descriptors)  |                Normal
0x80500000 |--------------------------|             ------------
           |           Heap           |                Normal
           |--------------------------|             ------------
           |          Stack           |                Normal
0x80400000 |--------------------------|             ------------
           |         ZI Data          |                Normal
0x80300000 |--------------------------|             ------------
           |         RW Data          |                Normal
0x80200000 |--------------------------|             ------------
           |         RO Data          |                Normal
           |--------------------------|             ------------
           |         RO Code          |              USH Normal
0x80000000 |--------------------------|             ------------
           |      Daughterboard       |                Fault
           |      HSB AXI buses       |
0x40000000 |--------------------------|             ------------
           |      Daughterboard       |                Fault
           |  test chips peripherals  |
0x2C002000 |--------------------------|             ------------
           |     Private Address      |            Device Memory
0x2C000000 |--------------------------|             ------------
           |      Daughterboard       |                Fault
           |  test chips peripherals  |
0x20000000 |--------------------------|             ------------
           |       Peripherals        |           Device Memory RW/RO
           |                          |              &amp; Fault
0x00000000 |--------------------------|
*/

// L1 Cache info and restrictions about architecture of the caches (CCSIR register):
// Write-Through support *not* available
// Write-Back support available.
// Read allocation support available.
// Write allocation support available.

// Note: You should use the Shareable attribute carefully.
// For cores without coherency logic (such as SCU) marking a region as shareable forces the processor to not cache that region regardless of the inner cache settings.
// Cortex-A versions of RTX use LDREX/STREX instructions relying on Local monitors. Local monitors will be used only when the region gets cached, regions that are not cached will use the Global Monitor.
// Some Cortex-A implementations do not include Global Monitors, so wrongly setting the attribute Shareable may cause STREX to fail.
   
// Recall: When the Shareable attribute is applied to a memory region that is not Write-Back, Normal memory, data held in this region is treated as Non-cacheable.
// When SMP bit = 0, Inner WB/WA Cacheable Shareable attributes are treated as Non-cacheable.
// When SMP bit = 1, Inner WB/WA Cacheable Shareable attributes are treated as Cacheable.
   
// Following MMU configuration is expected
// SCTLR.AFE == 1 (Simplified access permissions model - AP[2:1] define access permissions, AP[0] is an access flag)
// SCTLR.TRE == 0 (TEX remap disabled, so memory type and attributes are described directly by bits in the descriptor)
// Domain 0 is always the Client domain
// Descriptors should place all memory in domain 0

#include "&lt;Device&gt;.h" /* ToDo: replace '&lt;Device&gt;' with your device name */

// L2 table pointers
//-----------------------------------------------------
#define PRIVATE_TABLE_L2_BASE_4k       (0x80504000) //Map 4k Private Address space
#define SYNC_FLAGS_TABLE_L2_BASE_4k    (0x80504C00) //Map 4k Flag synchronization
#define PERIPHERAL_A_TABLE_L2_BASE_64k (0x80504400) //Map 64k Peripheral #1 
#define PERIPHERAL_B_TABLE_L2_BASE_64k (0x80504800) //Map 64k Peripheral #2 

//--------------------- PERIPHERALS -------------------
#define PERIPHERAL_A_FAULT             (0x00000000 + 0x1C000000) 
#define PERIPHERAL_B_FAULT             (0x00100000 + 0x1C000000) 

//--------------------- SYNC FLAGS --------------------
#define FLAG_SYNC                       0xFFFFF000
#define F_SYNC_BASE                     0xFFF00000  //1M aligned

//Import symbols from linker
extern uint32_t Image$$VECTORS$$Base;
extern uint32_t Image$$RW_DATA$$Base;
extern uint32_t Image$$ZI_DATA$$Base;
extern uint32_t Image$$TTB$$ZI$$Base;

static uint32_t Sect_Normal;        // outer &amp; inner wb/wa, non-shareable, executable, rw, domain 0, base addr 0
static uint32_t Sect_Normal_Cod;    // outer &amp; inner wb/wa, non-shareable, executable, ro, domain 0, base addr 0
static uint32_t Sect_Normal_RO;     // as Sect_Normal_Cod, but not executable
static uint32_t Sect_Normal_RW;     // as Sect_Normal_Cod, but writeable and not executable
static uint32_t Sect_Device_RO;     // device, non-shareable, non-executable, ro, domain 0, base addr 0
static uint32_t Sect_Device_RW;     // as Sect_Device_RO, but writeable
                                       
/* Define global descriptors */        
static uint32_t Page_L1_4k  = 0x0;  // generic
static uint32_t Page_L1_64k = 0x0;  // generic
static uint32_t Page_4k_Device_RW;  // shared device, not executable, rw, domain 0
static uint32_t Page_64k_Device_RW; // shared device, not executable, rw, domain 0

void MMU_CreateTranslationTable(void)
{
  mmu_region_attributes_Type region;

  // Create 4GB of faulting entries
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, 0, 4096, DESCRIPTOR_FAULT);

  /*
   * Generate descriptors. Refer to core_ca.h to get information about attributes
   *
   */
  // Create descriptors for Vectors, RO, RW, ZI sections
  section_normal(Sect_Normal, region);
  section_normal_cod(Sect_Normal_Cod, region);
  section_normal_ro(Sect_Normal_RO, region);
  section_normal_rw(Sect_Normal_RW, region);
  // Create descriptors for peripherals
  section_Device_ro(Sect_Device_RO, region);
  section_Device_rw(Sect_Device_RW, region);
  // Create descriptors for 64k pages
  page64k_Device_rw(Page_L1_64k, Page_64k_Device_RW, region);
  // Create descriptors for 4k pages
  page4k_Device_rw(Page_L1_4k, Page_4k_Device_RW, region);

  /*
   *  Define MMU flat-map regions and attributes
   *
   */
  // Define Image
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, (uint32_t)&amp;Image$$VECTORS$$Base     ,    1U, Sect_Normal_Cod);
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, (uint32_t)&amp;Image$$RW_DATA$$Base     ,    1U, Sect_Normal_RW);
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, (uint32_t)&amp;Image$$ZI_DATA$$Base     ,    1U, Sect_Normal_RW);

  // All DRAM executable, RW, cacheable - applications may choose to divide memory into RO executable
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, (uint32_t)&amp;Image$$TTB$$ZI$$Base     , 2043U, Sect_Normal);

  //--------------------- PERIPHERALS -------------------
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_FLASH_BASE0    ,   64U, Sect_Device_RO);
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_FLASH_BASE1    ,   64U, Sect_Device_RO);
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_SRAM_BASE      ,   64U, Sect_Device_RW);
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_VRAM_BASE      ,   32U, Sect_Device_RW);
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_ETHERNET_BASE  ,   16U, Sect_Device_RW);
  MMU_TTSection (&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_USB_BASE       ,   16U, Sect_Device_RW);
                                                                                
  // Create (16 * 64k)=1MB faulting entries to cover peripheral range           
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, PERIPHERAL_A_FAULT                   ,   16U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, DESCRIPTOR_FAULT);
  // Define peripheral range                                                    
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_DAP_BASE        ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_SYSTEM_REG_BASE ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_SERIAL_BASE     ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_AACI_BASE       ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_MMCI_BASE       ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_KMI0_BASE       ,    2U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_UART_BASE       ,    4U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_WDT_BASE        ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_A_TABLE_L2_BASE_64k, Page_64k_Device_RW);
                                                                                
  // Create (16 * 64k)=1MB faulting entries to cover peripheral range           
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, PERIPHERAL_B_FAULT                   ,   16U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, DESCRIPTOR_FAULT);
  // Define peripheral range                                                    
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_TIMER_BASE      ,    2U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_DVI_BASE        ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_RTC_BASE        ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_UART4_BASE      ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);
  MMU_TTPage64k(&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_CLCD_BASE       ,    1U, Page_L1_64k, (uint32_t *)PERIPHERAL_B_TABLE_L2_BASE_64k, Page_64k_Device_RW);

  // Create (256 * 4k)=1MB faulting entries to cover private address space. Needs to be marked as Device memory
  MMU_TTPage4k (&amp;Image$$TTB$$ZI$$Base, __get_CBAR()                         ,  256U,  Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, DESCRIPTOR_FAULT);
  // Define private address space entry
  MMU_TTPage4k (&amp;Image$$TTB$$ZI$$Base, __get_CBAR()                         ,    2U,  Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, Page_4k_Device_RW);
  // Define L2CC entry
  MMU_TTPage4k (&amp;Image$$TTB$$ZI$$Base, &lt;DeviceAbbreviation&gt;_L2C_BASE        ,    1U,  Page_L1_4k, (uint32_t *)PRIVATE_TABLE_L2_BASE_4k, Page_4k_Device_RW);

  // Create (256 * 4k)=1MB faulting entries to synchronization space (Useful if some non-cacheable DMA agent is present in the SoC)
  MMU_TTPage4k (&amp;Image$$TTB$$ZI$$Base, F_SYNC_BASE                          ,  256U, Page_L1_4k, (uint32_t *)SYNC_FLAGS_TABLE_L2_BASE_4k, DESCRIPTOR_FAULT);
  // Define synchronization space entry.                       
  MMU_TTPage4k (&amp;Image$$TTB$$ZI$$Base, FLAG_SYNC                            ,    1U, Page_L1_4k, (uint32_t *)SYNC_FLAGS_TABLE_L2_BASE_4k, Page_4k_Device_RW);

  /* Set location of level 1 page table
  ; 31:14 - Translation table base addr (31:14-TTBCR.N, TTBCR.N is 0 out of reset)
  ; 13:7  - 0x0
  ; 6     - IRGN[0] 0x1  (Inner WB WA)
  ; 5     - NOS     0x0  (Non-shared)
  ; 4:3   - RGN     0x01 (Outer WB WA)
  ; 2     - IMP     0x0  (Implementation Defined)
  ; 1     - S       0x0  (Non-shared)
  ; 0     - IRGN[1] 0x0  (Inner WB WA) */
  __set_TTBR0(((uint32_t)&amp;Image$$TTB$$ZI$$Base) | 0x48);
  __ISB();

  /* Set up domain access control register
  ; We set domain 0 to Client and all other domains to No Access.
  ; All translation table entries specify domain 0 */
  __set_DACR(1);
  __ISB();
}
</pre> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="templates_pg.html">CMSIS-Core Device Templates</a></li>
    <li class="footer">Generated on Wed Jul 10 2019 15:20:27 for CMSIS-Core (Cortex-A) Version 1.1.4 by Arm Ltd. All rights reserved.
	<!--
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 
	-->
	</li>
  </ul>
</div>
</body>
</html>
